<?
/*
***************MainForm******************	
*	Created by Doron Rainer		*
*****************************************
*/
class form {
	private $method,$action,$style;
	private $fields = array(); // An array to keep fields
	private $numOfFields; // Counter of fields
	//Deafult constructor! must get Method = $met, Action=$act! Style (=$style) is not required! but it can be added...
	public function form ( $met , $act, $style="")
	{
		if (!$met or !$act) 
		{
			//Error 1000: action or method didn't inserted!
			return 1000;
		} else
		{
			$this->method = $met;
			$this->action = $act;
			$this->style = $style;
			$this->numOfFields = 0;
		}
	}

	protected function insert($object)
	{
		$this->fields[$this->numOfFields] = (object) $object;
		$this->numOfFields++;
	}
	protected function remove($name)
	{
		for ($i=0;$i <= count($this->fields); $i++) {
			if ($this->fields[$i]->getName() == $name)
			{
				for ($x = $i; $x <= count($this->fields); $x++)
				{
					if ($x+1 < count($this->fields)) {
						$this->fields[$x] = $this->fields[$x+1];
					}
				}
			$this->numOfFields--;
			break;
			}
		}
	}
	public function setAction($act)
	{
		if (!$act)
		{
			$this->action = $act;	
		} else
		{
			//Error 1001: action didn't inserted.
			return 1001;
		}
	}
	public function setMethod($met)
	{
		if (!$met)
		{
			$this->method = $met;
		} else
		{
			//Error 1002: Method didn't inserted;
			return 1002;
		}
	}
	public function createForm()
	{
		if ($this->style != "")
		{
			$out="<form action='{$this->action}' method='{$this->method}' style='{$this->style}'>";
		} else
		{
			$out="<form action='{$this->action}' method='{$this->method}'>";
		}
		for ($i = 0;$i < $this->numOfFields; $i++)
		{
			$out .= $this->fields[$i]->createObject();
				
		}
		$out.="</form>\n";
		return $out;
	}

}
?>
